<form id="newsletterForm" method="post" action="<?php echo str_replace('&', '&amp;', $action); ?>">
    <input class="txtInput" id="subscriber_name" name="subscriber_name" placeholder="Indtast dit navn.....">   
	<input class="txtInput" id="subscriber_email" name="subscriber_email" placeholder="Indtast din e-mail adresse....."> 
	<a href="#" id="subscriber_button1" class="btn btnTilmeld">tilmeld</a> 
	<a class="btn btnAfmeld" id="unsubscriber_button1" href="#">Afmeld </a> 
</form>

<script type="text/javascript">
	//var mail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;     	
	var mail_filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,6})+$/;
	var post = false;
	
	//jQuery('#subscriber_button1').live('click', function(event){
	jQuery('#subscriber_button1').bind('click', function(event){
		event.preventDefault();						
		
		if(jQuery('#subscriber_name').val() == ''){ // || (jQuery('#subscriber_name').val() == jQuery('#subscriber_name').attr('title'))){ 	
			//confirm('Nyhedsbrev', 'Navn er ugyldig. Indtast en gyldig navn.', 'notify');
			show_popup('Navn er ugyldig. Indtast en gyldig navn.');

			return false;
		}
		
		if(!mail_filter.test(jQuery('#subscriber_email').val())){  
			//confirm('Nyhedsbrev', 'E-mail "' + jQuery('#subscriber_email').val() + '" er ugyldig. <br />Indtast en gyldig e-mail-adresse!', 'notify');
			//confirm('Nyhedsbrev', 'E-mailen er ugyldig. Indtast en gyldig e-mail.', 'notify');
			show_popup('E-mailen er ugyldig. Indtast en gyldig e-mail.');

			return false;
		}		

        if(!post){
			/*
            jQuery.post(
                "<?php //echo $subscriber_url; ?>",
                {'email': jQuery('#subscriber_email').val(), 'name': jQuery('#subscriber_name').val()},
                function(data){
                    confirm('Nyhedsbrev', data, 'notify');

                    //jQuery('#subscriber_email').focus();

                    // Unknown bug, this button has been called 2 times.
                    post = true;
                }
            );
			*/
			jQuery.ajax({
				type: "POST",
				url: "<?php echo $subscriber_url; ?>",
				data: {'email': jQuery('#subscriber_email').val(), 'name': jQuery('#subscriber_name').val()},
				dataType: "text",
				success: function(data, text, request) { 
					//confirm('Nyhedsbrev', data, 'notify');
					show_popup(data);
					post = true;
				} ,
				complete: function(xhr, status) {
					//setTimeout(closePopup, 9000); 					
				},
				async: false
			});
        }
        else{
            post = false;
        }
		//jQuery('#subscriber_email').val('');		
		//jQuery('#subscriber_name').val('');		
		//jQuery('#TB_closeWindowButton').trigger('click');
		
		return false;
	});
	
	//jQuery('#unsubscriber_button1').live('click', function(event){
	jQuery('#unsubscriber_button1').bind('click', function(event){
		event.preventDefault();
		
		if(!mail_filter.test(jQuery('#subscriber_email').val())){  
			//confirm('Nyhedsbrev', 'E-mail "' + jQuery('#subscriber_email').val() + '" er ugyldig. <br />Indtast en gyldig e-mail-adresse!', 'notify');
			//confirm('Nyhedsbrev', 'E-mailen er ugyldig. Indtast en gyldig e-mail.', 'notify');
			show_popup('E-mailen er ugyldig. Indtast en gyldig e-mail.');

			return false;
		}
		
		if(!post){
			/*
			jQuery.post(
				"<?php echo $unsubscriber_url; ?>", 
				{email: jQuery('#subscriber_email').val()},
				function(data){                    
					confirm('Nyhedsbrev', data, 'notify');				
					
					jQuery('#subscriber_email').focus();				
				}
			);
			*/
			jQuery.ajax({
				type: "POST",
				url: "<?php echo $unsubscriber_url; ?>", 
				data: {email: jQuery('#subscriber_email').val()},
				dataType: "text",
				success: function(data, text, request) { 
					//confirm('Nyhedsbrev', data, 'notify');
					show_popup(data);
					post = true;
				} ,
				complete: function(xhr, status) {
					//setTimeout(closePopup, 9000); 					
				},
				async: false
			});
		}
		else{
			post = false;
		}
		//jQuery('#subscriber_email').val('');
		//jQuery('#subscriber_name').val('');		
		
		return false;  
	});   
	
	jQuery('#newsletterForm').live('submit', function(event){		
		event.preventDefault();				
	});
	
	jQuery('#TB_closeWindowButton').bind('click', function(event){		
		jQuery('#subscriber_email').val('');
		jQuery('#subscriber_name').val('');
		
		post = false;
	});
	
	/*
	jQuery(document).ready(function(){        
		var hint = 'Indtast din email adresse...';
		jQuery('#subscriber_email').focus(function(e) {
			if (jQuery(this).val() == hint) {
				jQuery(this).val('');
			}
		});
		jQuery('#subscriber_email').blur(function(e) {
			if (jQuery(this).val() == '') {
				jQuery(this).val(hint);
			}
		});
	});
	*/

    function closePopup(){
		jQuery('#subscriber_email').val('');
		jQuery('#subscriber_name').val('');
		
		//jQuery('#TB_closeWindowButton').trigger('click'); 
    }
</script>